// import RecordItem from '@/custom.d.ts';
import clone from '@/lib/clone.ts';

const localStorageKeyName = 'recordList';

const recordStore = {
    recordList: [] as RecordItem[],
    fetchRecords() {
        this.recordList = JSON.parse(window.localStorage.getItem(localStorageKeyName) || '[]') as RecordItem[];
        return this.recordList;
    },
    //recordList: Record[]这里是由Record类型组成的数组的类型
    createRecords(record: RecordItem) {
        const record2: RecordItem = clone(record);
        this.recordList.push(record2);
        this.saveRecords();
    },
    saveRecords() {
        window.localStorage.setItem(localStorageKeyName, JSON.stringify(this.recordList));
    }
};
recordStore.fetchRecords();
export default recordStore;